<?php
/**
 * @license http://www.gnu.org/licenses/lgpl.html LGPL
 * @author Harlan Iverson <h dot iverson at gmail dot com>
 * @copyright Copyright (c) 2006, Harlan Iverson.
 * @version $Id$
 */


require_once( "TestHarness.php" );

/**
 * Test the VariableResolver. It currently does not use its own faces-config.xml, it goes
 * straige to the context. This is some of the first faces code ever written, so bear 
 * with it for now.
 */
class PhpFaces_Test_Lang_ListObjectTest extends PhpUnit2_Framework_TestCase {
	public function testCreateNull() {
		$o = new PhpFaces_Lang_ListObject();
		$o->add( "item" );
		$o->add( "some other item" );
		
		$this->assertEquals( 2, $o->getSize() );
	}
	
	public function testCreateFromArray() {
		
		$list = array( "item", "some other item" );
		$o = new PhpFaces_Lang_ListObject( $list );
		
		$this->assertEquals( 2, $o->getSize() );
	}
	
	public function testRemove() {
		
		$list = array( "item", "some other item" );
		$o = new PhpFaces_Lang_ListObject( $list );
		
		$o->remove( 0 );
		$this->assertEquals( 1, $o->getSize() );
		$o->remove( 0 );
		$this->assertEquals( 0, $o->getSize() );
		/* TODO
		try {
			$o->remove( 0 );
			$this->fail( "Should have gotten an exception." );
		} catch( Excetpion $e ) {
			
		}
		*/
	}
	
	public function testAsArray() {
		$list = array( "item", "some other item" );
		$o = new PhpFaces_Lang_ListObject( $list );
		
		$retList = $o->asArray();
		
		$this->assertNotNull( $retList, $retList );
		$this->assertEquals( $list, $retList );
	}
	
	public function testArrayAccessForEach() {
		$list = array( "item", "some other item" );
		$o = new PhpFaces_Lang_ListObject( $list );
		
		$i = 0;
		foreach( $o as $valu ) {
			$i++;
		}
		
		$this->assertEquals( 2, $i );
	}
}

?>